package com.bjshiwei.zhengu.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bjshiwei.zhengu.R;
import com.bjshiwei.zhengu.bean.IndividualMsgBean;

import java.util.List;

/**
 * 作者：Administrator on 2016/10/14 0014 16:00
 * 邮箱：sanjins@126.com
 */


public class IndividualMsgAdapter extends  MyBaseAdapter<IndividualMsgBean.DataBean>{
    private Context mContext;
    private List<IndividualMsgBean.DataBean> mData;
    public IndividualMsgAdapter(Context context, List<IndividualMsgBean.DataBean> datas) {
        super(context, datas);
        mContext = context;
        mData = datas;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_individual_message, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }


        if(!TextUtils.isEmpty(mData.get(position).getTicker())) {
            viewHolder.mTextViewticker.setText("("+mData.get(position).getTicker()+")");
        }
        if(!TextUtils.isEmpty(mData.get(position).getName())) {
            viewHolder.mTextViewName.setText(mData.get(position).getName());
        }
        if(!TextUtils.isEmpty(mData.get(position).getTitle())) {
            viewHolder.mTextViewTitle.setText(mData.get(position).getTitle());
        }
        if(!TextUtils.isEmpty(mData.get(position).getInsertTime())) {
            String substring = mData.get(position).getInsertTime().substring(5, 11);
            viewHolder.mTextViewInsertTime.setText(substring);
        }

        if(position==mData.size()-1) {
            viewHolder.mTextViewFoot.setVisibility(View.GONE);
        }else {
            viewHolder.mTextViewFoot.setVisibility(View.GONE);
        }

//        viewHolder.mViewLine.setBackgroundColor(new RandomColor().randomColor());

        return convertView;
    }

    public static class ViewHolder{
        private TextView mTextViewName,mTextViewticker,mTextViewTitle,mTextViewInsertTime;
        private View mViewLine;
        private TextView mTextViewFoot;
        public ViewHolder(View view){
            mTextViewticker = (TextView) view.findViewById(R.id.tv_individual_msg_ticker);
            mTextViewTitle = (TextView) view.findViewById(R.id.tv_individual_msg_title);
            mTextViewInsertTime = (TextView) view.findViewById(R.id.tv_individual_msg_inserttime);
            mViewLine = view.findViewById(R.id.v_individual_vertical_line);
            mTextViewName = (TextView) view.findViewById(R.id.tv_individual_msg_name);
            mTextViewFoot = (TextView) view.findViewById(R.id.tv_individual_message_foot);
        }
    }
}
